package com.zzyl.nursing.controller;

import com.huaweicloud.sdk.iotda.v5.model.ServiceCapability;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Device;
import com.zzyl.nursing.dto.DeviceDto;
import com.zzyl.nursing.service.IDeviceService;
import com.zzyl.nursing.vo.DeviceReportDataVo;
import com.zzyl.nursing.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备管理Controller
 * 
 * @author zhq
 * @date 2025-08-21
 */
@Api(tags = "设备管理管理")
@RestController
@RequestMapping("/nursing/device")
public class DeviceController extends BaseController
{
    @Autowired
    private IDeviceService deviceService;

    /**
     * 查询报警功能列表
     */
    @ApiOperation("查询报警功能列表")
    @PreAuthorize("@ss.hasPermi('nursing:alertRule:list')")
    @GetMapping("/queryProduct/{productKey}")
    public R<List<ServiceCapability>> queryProduct(@PathVariable String productKey)
    {
        return R.ok(deviceService.queryProduct(productKey));
    }

    @GetMapping("/queryServiceProperties/{iotId}")
    @ApiOperation("查询设备上报数据")
    public R<List<DeviceReportDataVo>> queryServiceProperties(@PathVariable String iotId){
        return R.ok( deviceService.queryServiceProperties(iotId));

    }


    @GetMapping("/{iotId}")
    @ApiOperation("根据iotId查询设备")
    public AjaxResult getinfo(@PathVariable String iotId){
        return success(deviceService.queryDeviceByDetail(iotId));
    }
    @PostMapping("/syncProductList")
    public AjaxResult syncProductList(){
        deviceService.syncProductList();
        return AjaxResult.success();
    }

    /**
     * 查询设备管理列表
     */
    @ApiOperation("查询所有设备")
    @GetMapping("/allProduct")
    public R<List<ProductVo>> allProduct()
    {
        List<ProductVo> list=deviceService.allProduct();
        return R.ok(list);
    }

    @ApiOperation("注册设备")
    @PostMapping("/register")
    public AjaxResult registerDevice(@RequestBody DeviceDto deviceDto){
        deviceService.registerDevice(deviceDto);
        return success();
    }
    @ApiOperation("查询智能设备列表")
    @PreAuthorize("@ss.hasPermi('nursing:device:list')")
    @GetMapping("/list")
    public TableDataInfo<List<Device>> list(@ApiParam("智能设备查询条件") Device device)
    {
        startPage();
        List<Device> list = deviceService.selectDeviceList(device);
        return getDataTable(list);
    }

}
